package com.atguigu.servicebase.handler;

import com.atguigu.commonutils.ExceptionUtil;
import com.atguigu.commonutils.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author zhaolie
 * @Date 2020/12/2 3:54 下午
 * @Version 1.0
 * @Description 统一异常处理类
 */

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class) // 指定出现什么异常执行这个方法
    @ResponseBody
    public Response error(Exception e) {
        e.printStackTrace();
        log.error(ExceptionUtil.getMessage(e));
        return Response.Failed().message("执行全局异常处理...");
    }
}
